home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 10 / develop 10 code / Is it Art? / ArtMaker / utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-08  |  3.4 KB  |  137 lines  |  [TEXT/KAHL]

  1. # include     "Shell.h"
  2.  
  3. extern  Boolean        doneflag;
  4.  
  5. /* These are stolen from arith.c, so we don't have to include the ANSI library for
  6. 2 routines  */
  7. int
  8. abs(int i)
  9. {
  10.     if (i < 0)
  11.         return(-i);
  12.     return(i);
  13. }
  14.  
  15.  
  16. long
  17. labs(long i)
  18. {
  19.     if (i < 0)
  20.         return(-i);
  21.     return(i);
  22. }
  23.  
  24.  
  25. /****************************************************
  26. Quickdraw Things...
  27. *****************************************************/
  28.  
  29. /*------------------------------------------------------------------------
  30. NewPixImage()            Creates pix image and inits the fields of the pixmap...
  31. ------------------------------------------------------------------------*/
  32.  
  33. Boolean NewPixImage(PixMapHandle ThePix, Rect *TheRect, short dpth)
  34. {
  35.     Ptr                    ThePtr;
  36.     long                Offrowbytes, ptrsize;
  37.     
  38.     Offrowbytes    =(((dpth * (TheRect->right - TheRect->left)) + 15) / 16) * 2;
  39.     ptrsize = (TheRect->bottom - TheRect->top) * Offrowbytes;
  40.     ThePtr = NewPtr(ptrsize);
  41.     if(MemError() != noErr)
  42.         return(false);
  43.     
  44.     (**ThePix).baseAddr = ThePtr;
  45.     (**ThePix).rowBytes = Offrowbytes + 0x8000;
  46.     (**ThePix).bounds = *TheRect;
  47.     (**ThePix).pixelSize = dpth;
  48.     (**ThePix).cmpCount = 1;
  49.     (**ThePix).cmpSize = dpth;
  50.     return(true);
  51. }
  52.     
  53.  
  54. /*------------------------------------------------------------------------
  55. NewBitMap()            Creates bit image and inits the fields of the bitmap...
  56. ------------------------------------------------------------------------*/
  57.  
  58. Boolean NewBitMap(BitMap *TheMap, Rect *TheRect)
  59. {
  60.     long    rb;
  61.     Ptr        ba;
  62.     
  63.     rb = ((TheRect->right - TheRect->left + 15) / 16) * 2;
  64.     ba = NewPtr(rb * (TheRect->bottom - TheRect->top));
  65.     if( MemError() == noErr)
  66.     {
  67.         TheMap->rowBytes = rb;
  68.         TheMap->baseAddr = ba;
  69.         TheMap->bounds = *TheRect;
  70.         return(true);
  71.     }
  72.     else
  73.         return(false);
  74. }
  75.  
  76. /*-------------------------------------------------------------------------
  77. CenterRect()             Centers theRect over thePt...
  78. --------------------------------------------------------------------------*/
  79. void CenterRect(Rect *theRect, Point *thePt)
  80. {
  81.     /* First home theRect... */
  82.     
  83.     OffsetRect(theRect, -theRect->left, -theRect->top);
  84.     
  85.     /* ...then center it over thePt */
  86.     
  87.      
  88.     thePt->h = thePt->h - (theRect->right / 2);
  89.     thePt->v = thePt->v - (theRect->bottom / 2);
  90.     OffsetRect(theRect, thePt->h, thePt->v);
  91. }
  92.  
  93. /*-------------------------------------------------------------------------
  94. Center()             Returns the center of the rect
  95. --------------------------------------------------------------------------*/
  96. Point Center(Rect *theRect)
  97. {
  98.     Point        pt;
  99.         
  100.     pt.h = theRect->left + ((theRect->right - theRect->left) / 2);
  101.     pt.v = theRect->top + ((theRect->bottom - theRect->top) / 2);
  102.     return(pt);
  103. }
  104.  
  105.  
  106. /*-------------------------------------------------------------------------
  107. These routines are from DTS Utilities
  108. --------------------------------------------------------------------------*/
  109. short    NumToolboxTraps(void)
  110. {
  111.     if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
  112.         return (0x200);
  113.     else
  114.         return (0x400);
  115. }
  116.  
  117. TrapType    GetTrapType(short theTrap)
  118. {
  119.     /* OS traps start with A0, Tool with A8 or AA. */
  120.     if ((theTrap & 0x0800) == 0)                    /* per D.A. */
  121.         return (OSTrap);
  122.     else
  123.         return (ToolTrap);
  124. }
  125.  
  126. Boolean TrapAvailable(short theTrap)
  127. {
  128.     TrapType    theTrapType;
  129.  
  130.     theTrapType = GetTrapType(theTrap);
  131.     if ((theTrapType == ToolTrap) && ((theTrap &= 0x07FF) >= NumToolboxTraps()))
  132.         theTrap = _Unimplemented;
  133.  
  134.     return (NGetTrapAddress(_Unimplemented, ToolTrap) != NGetTrapAddress(theTrap,
  135.                   theTrapType));
  136. }
  137.